/**
 *
 */
package com.module.boots.coder.view;

import java.sql.SQLException;

import org.apache.velocity.VelocityContext;

import com.module.boots.coder.base.BaseCoder;
import com.module.boots.coder.utils.MysqlBeanUtils;
import com.module.boots.coder.utils.PageUtils;

/**
 * 生成后端系统控制器
 * @author：溪云阁
 * @date：2020年9月4日
 */
public class ViewCoder extends BaseCoder {

    /**
     * 生成view控制类
     * @author 溪云阁
     * @throws SQLException void
     */
    public void createView() throws Exception {
        // 获取最基础的模板
        final VelocityContext context = getBaseContext(tableName);
        final String applicationPath = getBasePackagePath() + "/view/" + getUpperClassName(tableName).toLowerCase() + "/" + getUpperClassName(tableName) + "View.java";
        PageUtils.WriterPage(context, "view/view.ftl", applicationPath);
    }

    /**
     * 创建view出参
     * @author 溪云阁
     * @param voName 出参名称
     * @param voDescription 出参描述
     * @throws SQLException void
     */
    public void createVO(String voName, String voDescription) throws Exception {
        final VelocityContext context = getBaseContext(tableName);
        final String aoPath = getBasePackagePath() + "/view/" + getUpperClassName(tableName).toLowerCase() + "/vo/" + voName + "VO.java";
        context.put("voName", voName);
        context.put("voDescription", voDescription);
        context.put("feilds", MysqlBeanUtils.getOutFeilds(tableName));
        context.put("importTypes", MysqlBeanUtils.getOutPacking(tableName));
        PageUtils.WriterPage(context, "view/vo.ftl", aoPath);
    }

    /**
     * 创建view入参
     * @author 溪云阁
     * @param pvoName 入参类名称
     * @param pvoDescription 入参类描述
     * @throws SQLException void
     */
    public void createPVO(String pvoName, String pvoDescription) throws Exception {
        final String apoPath = getBasePackagePath() + "/view/" + getUpperClassName(tableName).toLowerCase() + "/pvo/" + pvoName + "PVO.java";
        final VelocityContext context = getBaseContext(tableName);
        context.put("pvoName", pvoName);
        context.put("pvoDescription", pvoDescription);
        context.put("feilds", MysqlBeanUtils.getInFeilds(tableName));
        context.put("importTypes", MysqlBeanUtils.getInPacking(tableName));
        PageUtils.WriterPage(context, "view/pvo.ftl", apoPath);
    }

}
